package com.cskaoyan.controller;

import com.cskaoyan.bean.MarketKeyword;
import com.cskaoyan.bean.MarketKeywordExample;
import com.cskaoyan.bean.bo.AdminKeywordsListBO;
import com.cskaoyan.bean.bo.KeywordCreateBO;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.vo.KeywordCreateVO;
import com.cskaoyan.bean.vo.SimpleRespVO;
import com.cskaoyan.service.AdminKeywordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author : gao
 * @since: 2022/10/13  15:37
 */
@RequestMapping("admin/keyword")
@RestController
public class AdminKeywordController {

    @Autowired
    AdminKeywordService adminKeywordService;

    @RequestMapping("list")
    public BaseRespVo<CommonData> listKeywords(AdminKeywordsListBO adminKeywordsListBO) {
        CommonData<MarketKeyword> data = adminKeywordService.listKeywords(adminKeywordsListBO);
        return BaseRespVo.ok(data, "成功");
    }

    @RequestMapping("create")
    public BaseRespVo<KeywordCreateVO> createKeywords(@RequestBody KeywordCreateBO keywordCreateBO) {
        KeywordCreateVO keywordCreateVO = adminKeywordService.createKeywords(keywordCreateBO);
        return BaseRespVo.ok(keywordCreateVO, "成功");
    }

    @RequestMapping("update")
    public BaseRespVo<MarketKeyword> updateKeywords(@RequestBody MarketKeyword marketKeyword) {
        MarketKeyword keyword = adminKeywordService.updateKeywords(marketKeyword);
        return BaseRespVo.ok(keyword,"成功");
    }

    @RequestMapping("delete")
    public SimpleRespVO deleteKeywords(@RequestBody MarketKeyword marketKeyword){
        Integer id = marketKeyword.getId();
        adminKeywordService.deleteKeyword(id);
        return SimpleRespVO.ok(0,"成功");
    }
}
